package com.lagou.mr.sort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class NumberSortBean implements WritableComparable<NumberSortBean> {

    //排序号
    private Long sortNum;
    //获取的数字
    private Long number;

    public NumberSortBean() {
    }

    public NumberSortBean(Long number,Long sortNum){
        this.number=number;
        this.sortNum = number;
    }

    @Override
    public int compareTo(NumberSortBean o) {
        //比较number大小，正序排序
        if(number>o.getNumber()){
            return 1;
        }else if(number<o.getNumber()){
            return -1;
        }else{
            return 0;
        }
    }

    //序列化
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(sortNum);
        dataOutput.writeLong(number);
    }
    //反序列化
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.sortNum = dataInput.readLong();
        this.number = dataInput.readLong();
    }

    @Override
    public String toString() {
        return  sortNum +"\t" + number;
    }


    public Long getSortNum() {
        return sortNum;
    }

    public void setSortNum(Long sortNum) {
        this.sortNum = sortNum;
    }

    public Long getNumber() {
        return number;
    }

    public void setNumber(Long number) {
        this.number = number;
    }
}
